<!--------------------------------------------------------------
>//	Company:	HTHK
>//	NAME:	    EmployeeSearch.jsp
>//	TITLE:	    Search Employ Information
>//	FUNCTION:	    Search Employ Information
>//	BY:	         Beyes Xia
>//	DATE:	    2004-1-13 9:38
>// --------------------------------------------------------------
-->

<%@ include file="../tssheader.jsp" %>
<%@ page import="tss.options.*" %>
<SCRIPT Language="Javascript" SRC="<%=contextPath%>/tss/employee/Calendar1-821.js"></script>
<%
    try
    {
    		StaffOptions esOptions=new StaffOptions();
    		EmployeeOptions edOptions = new EmployeeOptions("DEPARTMENT_CODE");
    		EmployeeOptions ecOptions = new EmployeeOptions("COST_CENTER");
    		EmployeeOptions epOptions = new EmployeeOptions("POSITION");
    		EmployeeOptions eeOptions = new EmployeeOptions("EMPLOYMENT_TYPE");
    			
        String str_staffName = session.getAttribute("s_staff_name")==null?"":(String)session.getAttribute("s_staff_name");
        String str_joinDateFrom = session.getAttribute("s_join_date_from")==null?"":(String)session.getAttribute("s_join_date_from");
        String str_joinDateTo = session.getAttribute("s_join_date_to")==null?"":(String)session.getAttribute("s_join_date_to");
        String str_department = session.getAttribute("s_department")==null?"":(String)session.getAttribute("s_department");
        String str_costCenter = session.getAttribute("s_cost_center")==null?"":(String)session.getAttribute("s_cost_center");
        String str_position = session.getAttribute("s_position")==null?"":(String)session.getAttribute("s_position");
        String str_employmentType = session.getAttribute("s_employment_type")==null?"":(String)session.getAttribute("s_employment_type");
        
%>
<body>

<script language="JavaScript1.1">
function mySubmit()
{
	if(checkDate(fm.join_date_from) && checkDate(fm.join_date_to) && checkFromTO())
	{
		fm.submit();
	}
}
function tss_calendar_from()
{
   var today = new Date();
   show_calendar('fm.join_date_from', today.getMonth(), today.getYear(), 'YYYY-MM-DD');
}
function tss_calendar_to()
{
   var today = new Date();
   show_calendar('fm.join_date_to', today.getMonth(), today.getYear(), 'YYYY-MM-DD');
}
function checkFromTO()
{
	if(fm.join_date_from.value.length!=0 && fm.join_date_to.value.length!=0 && fm.join_date_from.value>fm.join_date_to.value)
	{
		alert("Join Date From must be earlier than Join Date To");
		return false;
	}
	return true;
}
function checkDate(object) 
{
    var obj=object;
    var d = obj.value;
    if(d.length !=0 && d.length !=10)
    {
    		alert("Please input correct date with format as YYYY-MM-DD.");
    		return false;
    }	
    if(d.length==10)
    {
	    if (d.substring(4,5)!="-" || d.substring(7,8)!="-") 
	    {
		  alert("Please input correct date with format as YYYY-MM-DD.");
		  return false;
	    }
	    var day = d.substring(8,10);
	    var month = d.substring(5,7);
	    var year = d.substring(0,4);
	    if (day==null || isNaN(day)) 
	    {
			alert("Please input correct date with format as YYYY-MM-DD.");
			return false;
	    }
	    if (month==null || isNaN(month)) {
			alert("Please input correct date with format as YYYY-MM-DD.");
			return false;
	    }
	    if (day==null || isNaN(day)) {
			alert("Please input correct date with format as YYYY-MM-DD.");
			return false;
	    }
	    if (day < 1 || day > 31)
	    {
			alert("Please input correct date with format as YYYY-MM-DD.");
			return false;
	    }
	    if (month < 1 || month > 12) {
			alert("Please input correct date with format as YYYY-MM-DD.");
			return false;
	    }
	    if ((month==4 || month==6 || month==9 || month==11) && day==31) {
			alert("Please input correct date with format as YYYY-MM-DD.");
			return false;
	    }
	    if (month == 2) 
	    {
	        var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
	    		if (day > 29 || (day==29 && !isleap))
	    		 {
				alert("Please input correct date with format as YYYY-MM-DD.");
				return false;
	        	 }
	    } 
	}
    return true;
 }
</script> 

<h2>Employee Information Search</h2>
<form id=fm method=post action='<%=contextPath%>/servlet/tss.employee.EmployeeSearch' >
<table>

<tr>
  <td>Staff No:</td>
  <td>
          <select name=staff_name>
                  <%=esOptions.getOptions(str_staffName,false)%>
          </select>
  </td>
</tr>
<tr>
  <td>Position:</td>
  <td>
  		<select name=position>
                  <%=epOptions.getOptions(str_position)%>
          </select>
  </td>
</tr>
<tr>
  <td>Join Date:&nbsp;&nbsp;From</td>
  <td>
  	 <input type=text name='join_date_from' maxlength=10  ALIGN='LEFT' value=<%=str_joinDateFrom%> >
      <input type=button name=but_cal onClick="tss_calendar_from();" value='...'>(YYYY-MM-DD)
  </td>
</tr>
<tr>
  <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;To</td>
  <td>
  	 <input type=text name='join_date_to' maxlength=10  ALIGN='LEFT' value=<%=str_joinDateTo%> >
      <input type=button name=but_cal onClick="tss_calendar_to();" value='...'>(YYYY-MM-DD)
  </td>
</tr>
<tr>
  <td>Department:</td>
  <td>
  		<select name=department>
                  <%=edOptions.getOptions(str_department)%>
          </select>
  </td>
</tr>
<tr>
  <td>Cost Center:</td>
  <td>
  		<select name=cost_center>
                  <%=ecOptions.getOptions(str_costCenter)%>
          </select>
  </td>
</tr>
<tr>
  <td>Employment Type:</td>
  <td>
  		<select name=employment_type>
                  <%=eeOptions.getOptions(str_employmentType)%>
          </select>
  </td>
</tr>
</table>
<br>
<hr>
<p>  
  <INPUT type=button value='Export' onclick='mySubmit()'>
  <INPUT type=reset  value='Cancel'>
</p>
</form>
<%  }catch(Exception e) {
	out.println(e.toString());
}%>
<%@ include file="../tssfooter.jsp" %>
</body>
</html>
